package br.com.Login.controller;

import java.io.IOException;
import java.util.ArrayList;
import java.util.List;

import br.com.Health.connectionFactory.Hibernate.ConnectionFactoryInterfaceHibernate;
import br.com.Login.bean.Autorizacao;
import br.com.Login.bean.User;
import br.com.Login.dao.UserDao;

public class AutorizacaoController{

	private UserDao userDao;

	public List<Autorizacao> getAutorizacoes(ConnectionFactoryInterfaceHibernate connectionFactoryInterfaceHibernate) throws IOException {
		List<Autorizacao> aut = new ArrayList<Autorizacao>();
		userDao = new UserDao();
		aut = userDao.buscaAutorizacao(connectionFactoryInterfaceHibernate);
		return aut;
	}

	public List<Autorizacao> getAutorizacoesUsuario(User user, ConnectionFactoryInterfaceHibernate connectionFactoryInterfaceHibernate) throws IOException {
		List<Autorizacao> aut = getAutorizacoes(connectionFactoryInterfaceHibernate);
		aut.removeAll(user.getAutorizacoes());
		return aut;
	}

	public void concedePermissao(User user, List<Autorizacao> aut, ConnectionFactoryInterfaceHibernate connectionFactoryInterfaceHibernate) throws IOException {
		userDao = new UserDao();

		userDao.adicionaPermissao(user, aut, connectionFactoryInterfaceHibernate);
	}
}